#!/bin/bash
# version --202111221730
function checkAndSetVar() {
    # 检查变量
    if [ ! -n "${user}" ]; then
      echo "Because the user variable is empty, all use the default value:mysql"
      user=mysql
    elif [ ""${user} == "root" ]; then
        echo "you can't set the user variable is root, all use the default value:mysql"
        user=mysql
    fi
    #
    if [ ! -n "${id}" ]; then
      id=1
      echo "Because the id variable is empty, all use the default value:${id}"
    fi
    #
    if [ ! -n "${port}" ]; then
      port=3306
      echo "Because the port variable is empty, all use the default value:${port}"
    fi
    #
    if [ ! -n "${basedir}" ]; then
      basedir=/usr/local/mysql
      echo "Because the basedir variable is empty, all use the default value:${basedir}"
    fi
    #
    if [ ! -n "${datadir}" ]; then
        datadir=/usr/local/mysql/data
        echo "Because the datadir variable is empty, all use the default value:${datadir}"
    fi
    #
    if [ ! -n "${mysqltmp}" ]; then
        mysqltmp=${datadir}/tmp
        echo "Because the mysqltmp variable is empty, all use the default value:${mysqltmp}"
    fi
    #
    if [ ! -n "${sock}" ]; then
        sock=${mysqltmp}/mysql.sock
        echo "Because the sock variable is empty, all use the default value:${sock}"
    fi
    #
    if [ ! -n "${pidfile}" ]; then
        pidfile=${mysqltmp}/mysql.pid
        echo "Because the pidfile variable is empty, all use the default value:${pidfile}"
    fi
    #
    if [ ! -n "${logdir}" ]; then
        logdir=${datadir}/log
        echo "Because the logdir variable is empty, all use the default value:${logdir}"
    fi
    #
    if [ ! -n "${blogdir}" ]; then
        blogdir=${datadir}/blog
        echo "Because the blogdir variable is empty, all use the default value:${blogdir}"
    fi
    #
    if [ ! -n "${elogdir}" ]; then
        elogdir=${datadir}/elog
        echo "Because the blogdir variable is empty, all use the default value:${elogdir}"
    fi
    #
    if [ ! -n "${character}" ]; then
        character=utf8
        echo "Because the character variable is empty, all use the default value:${character}"
    fi

    echo -e "\033[34mThe values of the variables are:
    id=${id}
    user=${user}
    port=${port}
    basedir=${basedir}
    datadir=${datadir}
    mysqltmp=${mysqltmp}
    sock=${sock}
    pidfile=${pidfile}
    logdir=${logdir}
    blogdir=${blogdir}
    elogdir=${elogdir}
    character=${character}
    \033[0m"
}
function checkLoginVar() {
    # 检查变量
    if [ ! -n "${loginuser}" ]; then
        echo "Because the loginuser variable is empty, all use the default value:root"
        user=root
    fi
    if [ ! -n "${password}" ]; then
        echo "Because the password variable is empty, all use the default value:123456"
        password="123456"
    fi
    echo "The values of the variables are:
    loginuser=${loginuser}
    password=${password}
    "
}